function previewImage(file, callback) {//file为plupload事件监听函数参数中的file对象,callback为预览图片准备完成的回调函数
    if (!file || !/image\//.test(file.type)) return; //确保文件是图片
    if (file.type == 'image/gif') {//gif使用FileReader进行预览,因为mOxie.Image只支持jpg和png
        var fr = new mOxie.FileReader();
        fr.onload = function () {
            callback(fr.result);
            fr.destroy();
            fr = null;
        }
        fr.readAsDataURL(file.getSource());
    } else {
        var preloader = new mOxie.Image();
        preloader.onload = function () {
            preloader.downsize(300, 300);//先压缩一下要预览的图片,宽300，高300
            var imgsrc = preloader.type == 'image/jpeg' ? preloader.getAsDataURL('image/jpeg', 80) : preloader.getAsDataURL(); //得到图片src,实质为一个base64编码的数据
            callback && callback(imgsrc); //callback传入的参数为预览图片的url
            preloader.destroy();
            preloader = null;
        };
        preloader.load(file.getSource());
    }
};

 function plupimg(savedir) {
    var uploader1 = new plupload.Uploader({ //实例化一个plupload上传对象
        runtimes: 'html5,flash,silverlight,html4',
        browse_button: 'browse',
        multi_selection: false,
        auto_start: true,
        url: '/sys/attachment/upload',
        flash_swf_url: '/skin/scripts/plupload/Moxie.swf',
        silverlight_xap_url: '/skin/scripts/plupload/Moxie.xap',
        filters: {
            mime_types: [ //只允许上传图片文件
              { title: "图片文件", extensions: "jpg,jpeg,gif,png" }
            ]
        },
        init: {
            PostInit: function () {},
            FilesAdded: function (uploader, files) {
                uploader.start();//调用实例对象的start()方法开始上传文件 
                var file_name = files[0].name; //文件名
                !function () {
                    previewImage(files[0], function (imgsrc) {
                        $("#browse").html('<img src="' + imgsrc + '" />');
                        
                    })
                }();               
                /*
                for (var i = 0, len = files.length; i < len; i++) {                   
                    //构造html来更新UI
                    var html = '<li id="file-' + files[i].id + '"><p class="progress"></p></li>';
                    $(html).appendTo('#file-list');
                    !function (i) {
                        previewImage(files[i], function (imgsrc) {
                            $('#file-' + files[i].id).append('<img src="' + imgsrc + '" />');
                        })
                    }(i);
                }
                */
            },
            BeforeUpload: function (up, file) {
                // var filename = 'front-'+$('#adduserid').val()+get_suffix(file.name);
                //  set_upload_param(up, filename);
            },

            UploadProgress: function (up, file) {
                console.log('上传进度:' + file.percent);            
            },
            FileUploaded: function (uploader, files, data) {
                var data = $.parseJSON(data.response);
                if (data.status == 1) {
                    $('.browse').val(data.filepath);
                }else{
                    alert("图片上传过程失败！");
                }
            },
            Error: function (up, err) {
                console.log('上传出现失败:' + err.response);
            },
            Destroy: function (up, err) {
                console.log('上传出现失败:' + err.response);
            }
        }
    });
    uploader1.init();
 }

 function plupmulimg(savedir) {
     $("div.browse").each(function (i) {
         $(this).attr("id", "browse" + i);
     var uploader1 = new plupload.Uploader({ //实例化一个plupload上传对象
         //   runtimes: 'html5,flash,silverlight,html4',
         browse_button: 'browse'+i,
         multi_selection: false,
         auto_start: true,
         url: '/skin/tools/upload_ajax.ashx?action=plupload&dir=' + savedir,
         flash_swf_url: '/skin/scripts/plupload/Moxie.swf',
         silverlight_xap_url: '/skin/scripts/plupload/Moxie.xap',
         filters: {
             mime_types: [ //只允许上传图片文件
               { title: "图片文件", extensions: "jpg,gif,png" }
             ]
         },
         init: {
             PostInit: function () { },
             FilesAdded: function (uploader, files) {
                 uploader.start();//调用实例对象的start()方法开始上传文件 
                 var file_name = files[0].name; //文件名
                 !function () {
                     previewImage(files[0], function (imgsrc) {
                         $("#browse"+i).html('<img src="' + imgsrc + '" />');
                     })
                 }();
                 /*
                 for (var i = 0, len = files.length; i < len; i++) {                   
                     //构造html来更新UI
                     var html = '<li id="file-' + files[i].id + '"><p class="progress"></p></li>';
                     $(html).appendTo('#file-list');
                     !function (i) {
                         previewImage(files[i], function (imgsrc) {
                             $('#file-' + files[i].id).append('<img src="' + imgsrc + '" />');
                         })
                     }(i);
                 }
                 */
             },
             BeforeUpload: function (up, file) {
                 // var filename = 'front-'+$('#adduserid').val()+get_suffix(file.name);
                 //  set_upload_param(up, filename);
             },

             UploadProgress: function (up, file) {
                 console.log('上传进度:' + file.percent);
             },
             FileUploaded: function (uploader, files, data) {
                 var data = $.parseJSON(data.response);
                 if (data.status == 1) {
                     $('.browse'+i).val(data.filepath);
                 } else {
                     alert("图片上传过程失败！");
                 }
             },
             Error: function (up, err) {
                 console.log('上传出现失败:' + err.response);
             },
             Destroy: function (up, err) {
                 console.log('上传出现失败:' + err.response);
             }
         }
     });
     uploader1.init();
     });
 }

 function plupimg2(savedir) {
     /******************************************************ProgressBar********************************************************/
   //  var progressBar = $("#loading").progressbar({ width: '500px', color: '#B3240E', border: '1px solid #000000' });
     /******************************************************Plupload***********************************************************/
     //实例化一个plupload上传对象
     var uploader = new plupload.Uploader({
         browse_button: 'browse', //触发文件选择对话框的按钮，为那个元素id
         runtimes: 'html5,flash,silverlight,html4',//兼容的上传方式
         url: '/skin/tools/upload_ajax.ashx?action=plupload&dir=' + savedir,
         flash_swf_url: '/skin/scripts/plupload/Moxie.swf',
         silverlight_xap_url: '/skin/scripts/plupload/Moxie.xap',
         max_retries: 3,     //允许重试次数
         chunk_size: '10mb', //分块大小
         rename: true,  //重命名
         dragdrop: false, //允许拖拽文件进行上传
         unique_names: true, //文件名称唯一性
         filters: {
             mime_types: [ //只允许上传图片文件
               { title: "图片文件", extensions: "jpg,gif,png" }
             ]
         },        
         multi_selection: false //true:ctrl多文件上传, false 单文件上传  
     });

     //在实例对象上调用init()方法进行初始化
     uploader.init();

     uploader.bind('FilesAdded', function (uploader, files) {
         uploader.start();
         var file_name = files[0].name; //文件名
         !function () {
             previewImage(files[0], function (imgsrc) {
                 $("#browse").html('<img src="' + imgsrc + '" />');
             })
         }();
     });
     uploader.bind('UploadProgress', function (uploader, file) {
       //  var percent = file.percent;
      //   progressBar.progress(percent);
     });
     uploader.bind('FileUploaded', function (up, file, data) {
         if (data.status != 0) {
             alert("图片上传过程失败！");
         }
         alert(data.response);
         var data = $.parseJSON(data.msg);
      
     });
     uploader.bind('Error', function (up, err) {
         alert("文件上传失败,错误信息: " + err.message);
     });
     /******************************************************Plupload***********************************************************/
 }